<template>
  <div class="body">
    <div class="topbox">
      <span>工单编号:</span><input v-model="taskCode" type="text" placeholder="请输入">
      <span>工单状态:</span><input v-model="status" type="text" placeholder="请输入">
      <el-button type="primary" class="btn" @click="search">查询</el-button>
    </div>

    <div class="main">
      <el-button class="btn1" icon="el-icon-circle-plus-outline" @click="addData">新建</el-button>
      <button class="btn2" @click="disposition">工单配置</button>
      <el-table
        highlight-current-row
        :data="tableData"
        style="width: 100%"
        :header-cell-style="{
          backgroundColor: 'rgb(243, 246, 251)',
          fontWeight: 500,
          padding: '6px 0'
        }"
      >
        <el-table-column
          prop="taskStatus"
          label="序号"
          type="index"
        />
        <el-table-column
          prop="taskCode"
          label="工单编号"
        />
        <el-table-column
          prop="innerCode"
          label="设备编号"
        />
        <el-table-column
          prop="taskType.typeName"
          label="工单类型"
        />
        <el-table-column
          prop="desc"
          label="工单方式"
        />
        <el-table-column
          prop="taskStatusTypeEntity.statusName"
          label="工单状态"
        />
        <el-table-column
          prop="userName"
          label="运营人员"
        />
        <el-table-column
          prop="updateTime"
          label="创建日期"
          :formatter="formatDate"
        />
        <el-table-column
          label="操作"
          width="100"
        >
          <template #default="{row}"><a href="#" class="cl" @click="details(row.taskId)">查看详情</a></template>
        </el-table-column>
      </el-table>
    </div>
    <AutuSupply ref="AutuSupply" />
    <FindInfo :id="id" ref="FindInfo" :visible.sync="visible" />
    <WorkOrder ref="dialog" />
    <!-- 分页 -->
    <el-footer>
      <span>共{{ total }}条记录</span>&nbsp;&nbsp;
      <span>第{{ queryObj.pageIndex }}/{{ totalPage }}页</span>
      <el-pagination
        background
        style="float: right"
        :current-page="+queryObj.pageIndex"
        :page-size="+queryObj.pageSize"
        prev-text="上一页"
        next-text="下一页"
        layout="prev, next"
        :total="+total"
        @current-change="handleCurrentChange"
      />
    </el-footer>
  </div>
</template>

<script>
import { workOrderList } from '@/api/workOrder'
import AutuSupply from './components/autoSupply.vue'
import FindInfo from './components/findInfo.vue'
import WorkOrder from './components/WorkOrder.vue'
export default {
  name: 'DikedeIndex',
  components: {
    AutuSupply,
    FindInfo,
    WorkOrder
  },
  data () {
    return {
      totalPage: 0,
      tableData: [],
      dialogVisible: false,
      visible: false,
      queryObj: {
        pageIndex: 1,
        pageSize: 10,
        isRepair: false
      },
      taskCode: '',
      total: null,
      taskId: null,
      status: '',
      id: 0
    }
  },
  created () {
    this.dataList()
  },
  methods: {
    async dataList () {
      const data = await workOrderList(this.queryObj)
      this.queryObj.pageIndex = data.pageIndex
      this.queryObj.pageSize = data.pageSize
      this.total = data.totalCount
      this.totalPage = data.totalPage
      // console.log(data)
      this.tableData = data.currentPageRecords
    },
    formatDate (row, column) {
      // 获取单元格数据
      const datac = row[column.property]
      return datac.replace(/\-/g, '.').replace('T', ' ')
    },

    // 工单配置
    disposition () {
      this.$refs.AutuSupply.showDialog()
    },

    // 工单详情
    async details (id) {
      this.id = +id
      this.$nextTick(() => {
        this.$refs.FindInfo.getDetail()
      })
      this.visible = true
    },

    // 工单添加
    addData () {
      this.$refs.dialog.dialogVisibleOpen()
    },
    async  search () {
      // const data = await workOrderList(this.form)
      // console.log(data)
      if (this.taskCode) {
        this.tableData = this.tableData.filter(item => {
          return item.taskCode.includes(this.taskCode)
        })
      } else {
        return this.dataList()
      }
    },
    handleCurrentChange (val) {
      this.queryObj.pageIndex = val
      this.dataList()
    }

  }
}
</script>

<style lang="scss" scoped>

.el-footer {
  line-height: 60px;
  background-color: #fff;
  span {
    font-size: 16px;
    color: #dbdfe5;
  }
  .el-pagination {
    margin-top: 10px;
  }
}
::v-deep .btn-prev:disabled {
  background: #edf0f9 !important;
}
::v-deep .btn-next:disabled {
  background: #edf0f9 !important;
}
::v-deep .btn-prev{
 width: 70px;
 height: 32px;
 background-color: #d5ddf8 !important;
}
::v-deep .btn-next{
  margin: 0 20px;
 width: 70px;
 height: 32px;
 background-color: #d5ddf8 !important;
}
::v-deep .el-table {
 td {
  padding: 8px 0;
  border: none;
 }
 &::before {
  height: 0;
 }
}
.body {
  padding: 20px;
  .topbox {
    margin-bottom: 20px;
    background-color: #fff;
    padding-left: 17px;
    height: 64px;
    line-height: 64px;
    span {
      color: #606266;
      font-size: 14px;
      margin-right: 12px;
    }
    input {
      width: 209px;
      border: 1px solid #d8dde3;
      height: 36px;
      line-height: 36px;
      padding: 0 30px 0 15px;
      border-radius: 4px;
      margin-right: 8px;
    }
    input::placeholder{
      color: #ccc;
      font-size: 14px;
    }
    .btn{
      text-align: center;
      height: 36px;
      width: 80px;
      margin-right: 10px;
      background-color: #5f84ff;
    }
  }
  .main{
    background-color: #fff;
    .btn1{
      width: 80px;
      height: 36px;
      border:none;
      margin-right: 10px;
      border-radius: 4px;
      font-size: 14px;
      color: #fff;
      background: linear-gradient(135deg,#ff9743,#ff5e20)!important
    }
     .btn2{
      width: 80px;
      height: 36px;
      border:none;
      border-radius: 4px;
      font-size: 14px;
      color: #655b56;
      background-color: #fbf4f0!important;
      margin-bottom: 20px;
    }
  }
}
.cl {
  color: #5f84ff;
  font-size: 14px;
}

</style>
